<template>
  <div>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      :min-date="minDate"
      :max-date="maxDate"
      @confirm="confirm"
      @cancel="cancel"
      :formatter="formatter"
    />
  </div>
</template>

<script>
import moment from 'moment'
export default {
  name: '',
  props: {
    value: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      minDate: new Date(1997, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value)
    }
  },
  created () {
    this.a()
  },
  mounted () {},
  methods: {
    a () {
      console.log(this.currentDate)
      console.log(this.value)
    },
    confirm () {
      const currentDate = moment(this.currentDate).format('YYYY-MM-DD')
      this.$emit('input', currentDate)
      this.$emit('close')
    },
    cancel () {
      this.$emit('close')
    },
    formatter (type, val) {
      if (type === 'year') {
        return val + '年'
      }
      if (type === 'month') {
        return val + '月'
      }
      if (type === 'day') {
        return val + '日'
      }
      return val
    }
  }
}
</script>

<style scoped lang="less"></style>
